//
//  YCOrderUnSendTableViewCell.m
//  lianganyuchu
//
//  Created by iMac on 17/2/28.
//  Copyright © 2017年 杭州桑缇电子商务有限公司. All rights reserved.
//

#import "YCOrderUnSendTableViewCell.h"

@implementation YCOrderUnSendTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    CGFloat width=kMainScreen_Width-2*kDistance;
    [self.backView addShadowWith:CGSizeMake(width, 255)];
    
    self.headerView.layer.cornerRadius=2.0f;
    self.headerView.backgroundColor=MAIN_COLOR;
    
    self.iconLabel.layer.cornerRadius=20.0f;
    self.iconLabel.layer.masksToBounds=YES;
    [self.iconLabel setFont:[UIFont FontOfSize:18]];
    
    self.viewTop.layer.cornerRadius=2.0f;
    self.viewBottom.layer.cornerRadius=2.0f;
    
    [self.labStatus setFont:[UIFont LightFontOfSize:16]];
    [self.labOrderStatus setFont:[UIFont LightFontOfSize:16]];
    [self.labPhone setFont:[UIFont LightFontOfSize:18]];
    [self.labName setFont:[UIFont LightFontOfSize:13]];
    [self.labMeals setFont:[UIFont LightFontOfSize:17]];
    [self.labAddress setFont:[UIFont LightFontOfSize:14]];
    [self.labelTime setFont:[UIFont LightFontOfSize:14]];
    [self.label1 setFont:[UIFont LightFontOfSize:15]];
    [self.label2 setFont:[UIFont LightFontOfSize:15]];
    
    [self.label1 setTextColor:TEXT_MIDDLE];
    [self.label2 setTextColor:TEXT_MIDDLE];
    [self.labAddress setTextColor:TEXT_LIGHT];
    [self.labelTime setTextColor:TEXT_LIGHT];
    [self.labMeals setTextColor:TEXT_DEEP];
    [self.labPhone setTextColor:BLUE_COLOR];
    [self.labName setTextColor:TEXT_MIDDLE];
    [self.labOrderStatus setTextColor:MAIN_COLOR];
    [self.labStatus setTextColor:WHITE_COLOR];
    
    [self.btnPrint setBackgroundColor:WHITE_COLOR];
    self.btnPrint.layer.borderColor=MAIN_COLOR.CGColor;
    self.btnPrint.layer.borderWidth=1.0f;
    self.btnPrint.layer.borderWidth=1.0f;
    self.btnPrint.layer.cornerRadius=2.0f;
    
    [self.labPhone click:self action:@selector(phoneClicked:)];
    
    [self.btnExpress.titleLabel setFont:[UIFont LightFontOfSize:12]];
    [self.btnExpress setTitleColor:BLUE_COLOR forState:UIControlStateNormal];
    NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"查看物流状态"];
    NSRange strRange = {0,[str length]};
    [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:strRange];
    [self.btnExpress setAttributedTitle:str forState:UIControlStateNormal];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)btnPrintClicked:(id)sender
{
    self.printBlock(_order);
}

-(void)bindWith:(OrderTable *)order
{
    _order=order;
    CGFloat width=kMainScreen_Width-2*kDistance;
    CGFloat height=getTextSize(order.item_name, kMainScreen_Width-80, [UIFont LightFontOfSize:17]).height+getTextSize(order.addr_address, kMainScreen_Width-184, [UIFont LightFontOfSize:14]).height+255-39;
    [self.backView addShadowWith:CGSizeMake(width, height)];
    
    self.btnExpress.hidden=(order.show_express.intValue==0);
    self.btnExpressTopConstraint.constant=0;
    if (self.btnExpress.hidden) {
        self.labStatusTopConstraint.constant=27;
    }else{
        self.labStatusTopConstraint.constant=7;
    }
    
    [[App shared]readOrderColor];
    NSString *rgb1=[[App shared].dictColor objectForKey:order.status][@"status_color"];
    [self.headerView setBackgroundColor:colorFromHexCode(rgb1)];
    
    NSString *rgb2=[[App shared].dictColor objectForKey:order.status][@"text_color"];
    [self.labStatus setTextColor:colorFromHexCode(rgb2)];
    
    [self.labStatus setText:order.status_text];
    [self.labName setText:order.addr_name];
    [self.labPhone setText:order.addr_tele];
    [self.labOrderStatus setText:order.status_name];
    [self.iconLabel setText:order.num];
    [self.labMeals setText:order.item_name];
    
    [self.labelTime setText:order.meal_time];
    [self.labAddress setText:order.addr_address];
}
-(void)phoneClicked:(id)sender
{
     [self.labPhone callPhoneWith:_order.addr_tele];
}
- (IBAction)btnExpressClicked:(id)sender
{
    if (self.expressBlock) {
        self.expressBlock();
    }
}
@end


